/**
 * @filename:RegionalLinkedPricingServiceImpl 2019-01-17 14:56:43
 * @project skz  V1.3.3
 * Copyright(c) 2018 Liu,Wenzhao Co. Ltd. 
 * All right reserved. 
 */
package com.bingsum.service;

import com.bingsum.annotation.Api;
import com.bingsum.model.Driver;
import com.bingsum.util.ApiUtil;
import com.bingsum.util.ParaData;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.PageHelper;

import java.util.List;

import com.bingsum.model.RegionalLinkedPricing;
import com.bingsum.mapper.RegionalLinkedPricingMapper;
import tk.mybatis.mapper.entity.Example;

/**   
 *  
 * @Description:  [地区关联价位]——SERVICE
 * @Author:       Liu,Wenzhao   
 * @CreateDate:   2019-01-17 14:56:43
 * @Version:      V1.3.3
 *    
 */
@Service("regionalLinkedPricingService")
@Transactional(readOnly = true)
public class RegionalLinkedPricingService{

    @Autowired
    private RegionalLinkedPricingMapper regionalLinkedPricingMapper;

    @Api
    public List<ParaData> getRegionalLinkedPricingInfoList(ParaData pd) {

        return regionalLinkedPricingMapper.getRegionalLinkedPricingInfoList(pd);
    }

    @Api
    public Object getRegionalLinkedPricingInfo(ParaData pd) {
        Example example = new Example(RegionalLinkedPricing.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIsNull("deleteTime");
        criteria.andEqualTo("id", pd.getString("id"));
        RegionalLinkedPricing regionalLinkedPricing = regionalLinkedPricingMapper.selectOneByExample(example);

        if (regionalLinkedPricing == null){
            return ApiUtil.returnDescFail(pd,"无返回");
        }
        return regionalLinkedPricingMapper.getRegionalLinkedPricingInfo(pd);
    }

    @Api
    @Transactional(readOnly = false)
    public Object newRegionalLinkedPricingInfo(ParaData pd) {
        System.out.println(pd);
        RegionalLinkedPricing regionalLinkedPricing= pd.toBean(RegionalLinkedPricing.class);
        if (regionalLinkedPricing.getId() != null) {
            this.regionalLinkedPricingMapper.updateByPrimaryKeySelective(regionalLinkedPricing);
        } else {
            System.out.println("success");
            regionalLinkedPricingMapper.insert(regionalLinkedPricing);
        }
        return ApiUtil.returnOK(pd,regionalLinkedPricing);
    }

    @Api
    @Transactional(readOnly = false)
    public Object delRegionalLinkedPricing(ParaData pd) {
        regionalLinkedPricingMapper.delRegionalLinkedPricing(pd);
        RegionalLinkedPricing regionalLinkedPricing= pd.toBean(RegionalLinkedPricing.class);
        return ApiUtil.returnOK(pd,regionalLinkedPricing.getId());
    }

    @Api
    public List<ParaData> getRegAreaId(ParaData pd) {
        return regionalLinkedPricingMapper.getRegAreaId(pd);
    }
}